package com.zjw.video.common.entity.resp;

import com.zjw.video.common.entity.enums.RespCodeEnum;
import lombok.Data;

@Data
public class BaseResp<T> {
    private Integer code;
    private String msg;
    private T data;

    public BaseResp() {
    }

    public BaseResp(RespCodeEnum resultEnum) {
        this.code = resultEnum.getCode();
        this.msg = resultEnum.getMsg();
    }

    public static <T> BaseResp<T> success() {
        BaseResp<T> baseResp = new BaseResp<>(RespCodeEnum.SUCCESS);
        baseResp.data = null;
        return baseResp;
    }

    public static <T> BaseResp<T> success(T data) {
        BaseResp<T> baseResp = new BaseResp<>(RespCodeEnum.SUCCESS);
        baseResp.data = data;
        return baseResp;
    }

    public static <T> BaseResp<T> error(RespCodeEnum resultEnum) {
        return new BaseResp<T>(resultEnum);
    }

    public static <T> BaseResp<T> error(RespCodeEnum resultEnum, String msg) {
        BaseResp<T> baseResp = new BaseResp<>(resultEnum);
        baseResp.msg = msg;
        return baseResp;
    }

    public static <T> BaseResp<T> error(RespCodeEnum resultEnum, String msg, Throwable e) {
        BaseResp<T> baseResp = new BaseResp<T>(resultEnum);
        baseResp.msg = msg;
        return baseResp;
    }
}